#include "lib.h"
#include "stack.h"

int push_and_pop(int *push,int *pop,int len)
{
	int i = 0; 
	int j = 0;
	stack_s *stack =  stack_create(len);
	int data;
	int ret = 1;

	array_print(push,len,"push");
	array_print(pop,len,"pop");
	while (j < len) {
		while ((stack_is_empty(stack) == RET_END) || \
			((stack_top(stack, (void **)&data) == RET_OK))) {
			if (data == pop[j] ) {
				break;
			}
			if (i < len) {
				stack_push(stack,(void *)(push[i++]));
			} else {
				ret =  -1;
				break;
			}
		}
		if (stack_is_empty(stack) == RET_OK && \
			((stack_top(stack, (void **)&data) == RET_OK) && (data == pop[j] ))) {
			stack_pop(stack, NULL);
		}
		j++;
	}
	stack_destory(stack);
	
	printf("%s\n\n",ret>0?"true":"false");
	return ret;
}

int  main(int argc,char ** argv)
{
	int push[] = {1,2,3,4,5};
	int pop[100]  = {5,4,3,2,1};
	int i;
	
	for (i=0; i<atoi(argv[1]); i++) {
		push_and_pop(push,pop,sizeof(push)/sizeof(int));
		array_fill_with_rand_only(pop,sizeof(push)/sizeof(int));
	}
	return 0;
}







